import {
    fetchProduct
} from "@/api/gouwuche";

export default {
    namespaced: true,
    state: {
        tag: "产品模块store",
        products: []
    },
    mutations: {
        SET_PRODUCT(state, payload) {
            state.products = payload;
        },
        DECREMENT_INVENTORY(state, payload) {
            let target=state.products.find(item=>item.id===payload)
            if (target) {
                target.inventory--
            }
        },
    },
    actions: {
        async FETCH_PRODUCT(context, payload) {
            let res = await fetchProduct();
            console.log(res);
            context.commit("SET_PRODUCT", res.data)
        }
    },
    getters: {},
}